package com.atguigu.gmall.web.config;

import feign.Request;
import feign.RetryableException;
import feign.Retryer;

/**
 * @author 钟涛
 * @version 1.0
 * @description: TODO
 * @date 2021/12/18 10:41
 */
public class MyRetryer implements Retryer {

    private int count = 0;
    //feign不想继续重试，就直接抛异常
    @Override
    public void continueOrPropagate(RetryableException e) {
        //重试机制,重试三次
        if(count++ > 0){
            throw e; //重试结束
        }
        Request.HttpMethod method = e.method();
        String name = method.name();//远程调用的方法名,对方的ip地址 get http://192.168.XXX.XXX
        //TODO 编写预警信息,发送出去(发送给rabbitMQ、kafka)
    }

    @Override
    public Retryer clone() {
        return new MyRetryer();
    }
}
